function createVM(selector,data,func) {
    var orgData = {
        PageShow:false
        //表单验证常用字段
        ,rules:{
            notNull:{ validate: (val) => !!isTrue(val), message: '不能为空'}
            ,min:(min)=>{return { validate: (val) => val.length >= min, message: '字符长度不能小于' + min}}
            ,max:(max)=>{return { validate: (val) => val.length <= max, message: '字符长度不能大于' + max}}
            ,len:(len)=>{return { validate: (val) => val.length === len, message: '字符长度必须为' + len}}
            ,isPhone:{ validate: (val) => { var myreg=/^[1][3,4,5,6,7,8][0-9]{9}$/;if (!myreg.test(val)) {return false;} else {return true;}}, message: '手机号不合法'}
            ,isNum:{ validate: (val) => { var myreg=/^([0-9\.])+?$/;if (!myreg.test(val)) {return false;} else {return true;}}, message: '请输入数字'}
        }
        ,PageRefreshing:false
        ,PageLoadingMore:false
        ,selectChoices:{}
        // ,picFilePath:picFilePath
    }
    for(var i in data){
        orgData[i] = data[i]
    }

    var methods = {};

    methods["goback"]               = goback;
    methods["goto"]                 = goto
    methods["autoSubmit"]           = autoSubmit
    methods["isFalse"]              = isFalse
    methods["isTrue"]               = isTrue
    methods["boole"]                = isTrue
    methods["OnLoad"]               = function () {}
    methods["OnShow"]               = function () {}
    methods["OnHide"]               = function () {}
    methods["OnPullDownRefresh"]    = function () {}
    methods["OnPullUpLoadMore"]     = function () {}

    //检查角色权限的方法

    // methods["CanIUse"]                     = CanIUse;

    // methods["RoleWenYuan"]                 = RoleWenYuan;
    // methods["RoleFangLan"]                 = RoleFangLan;
    // methods["RoleRongJie"]                 = RoleRongJie;
    // methods["RoleZiGuan"]                  = RoleZiGuan;
    // methods["RoleJingLi"]                  = RoleJingLi;
    // methods["RoleAdmin"]                   = RoleAdmin;

    //常用的内置模板参数处理
    methods["isPic"]                        = isPic;
    // methods["download"]                     = download;

    for(var i in func){
        methods[i] = func[i]
    }

    var vue = new Vue({
        el:selector,
        delimiters: ['[[', ']]'],
        data:orgData,//基础数据
        methods:methods
    })
    return vue
}
function isPic(path) {
    if (!isTrue(path)){
        return false;
    }
    var suffix = get_suffix(path).toUpperCase().substring(1)
    log(suffix)
    if(suffix!="BMP"&&suffix!="JPG"&&suffix!="JPEG"&&suffix!="PNG"&&suffix!="GIF"){
        return false
    }else {
        return true
    }
}
function get_suffix(filename) {
    pos = filename.lastIndexOf('.')
    suffix = ''
    if (pos != -1) {
        suffix = filename.substring(pos)
    }
    return suffix;
}

function download (url,fileName) {
    if (!isTrue(url)){
        showToast("文件丢失")
        return false;
    }
    showToast("开始下载")
    var path = ""
    if (fileName !== undefined) {
        path = "/storage/emulated/0/qzyt/" + fileName + get_suffix(url);
    }else {
        path = "/storage/emulated/0/qzyt/" + random_string() + get_suffix(url);
    }

    api.download({
        url: url,
        savePath: path,
    }, function(ret, err) {
        if (ret.state == 1) {
            //下载成功
            showToast("下载成功")
        } else {

        }
    });
}

function autoSubmit() {
    var _this = this
    this.$refs.form.validate().then(function(result){
        if (result){
            var form = createForm(_this.en);
            apiPost("/app/fixed/add",form,function (res) {
                // log(res)
                Fixed.reload()
                _this.tab = 0
                _this.en = clearEn(_this.en)
                showToast(res.i)
            })

        }else{
            showToast("请检查输入")
        }
    });
}